home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
038a
/
aplibs91.zip
/
ERFIND.BAS
< prev
next >
Wrap
BASIC Source File
|
1991-06-28
|
8KB
|
228 lines
' ╔═════════════════════════════════════════════════════╗
' ║ E R F I N D . B A S ║
' ║ ║
' ║ THE PROGRAMMER'S FRIEND ... FOR QEDIT USERS ║
' ╚═════════════════════════════════════════════════════╝
' WAT ?? Well, here's the deal. I usually use PBC to complile my Power
' Basic programs due to the file sizes involved, and edit them with
' the very fine shareware editor QEdit. QEdit can jump on load to
' a given file line -- but how could I get the error info from my
' screen to the command line (other than manually, of course) ??
' Well, PB can read the screen buffer just fine. But it took me a lot
' of tinkering to create ERFIND.BAS, to take that info off the screen,
' get the line #, make it into a batch file, and then stuff the
' keyboard buffer with the batch file's name so that when ERFIND is
' done, the batch file starts automatically !!
' USAGE: START WITH A BATCH FILE LIKE 'pq.bat'. THIS CALLS FIRST THE
' COMPILER, THEN IF ERRLEVEL > 0 ERFIND IS CALLED. THEN THE NEW
' BATCH FILE, CREATED ON THE FLY, STARTS THE PROCESS ALL OVER AGAIN.
$COMPILE EXE
$OPTION CNTLBREAK OFF
DEFINT A-Z
DIM STATIC DispLine$ (25)
RD$ = ENVIRON$ ("TEMP") + ":" ' My environment contains the RamDisk
PRINT RD$: DELAY 2
' designator, eg SET TEMP=D, as a home
' for temporary files
CALL ReadNMatchColor ' set print color to = screen color @ cursor
DEFINT A-Z
''' dbg = -1 ' if true, 'dbg' creates an output
' file to help sort out the results.
IF dbg THEN
Debug = FREEFILE
OPEN "READSCRN.DBG" FOR APPEND AS #Debug
PRINT #Debug, "READSCRN -- "; TIME$; " "; DATE$
PRINT #Debug, " COMMAND$ = <"; COMMAND$; ">"
END IF
IF dbg THEN
PRINT #Debug, " RD$ = "; RD$
END IF
' read the screen
FOR L = 1 TO 25 ' into a string array
DispLine$ (L) = SCRNLINE$ (L)
NEXT
LOCATE CSRLIN + 2, 1
' find the last nonblank line
FOR L = 25 TO 1 STEP -1 ' (starting from the bottom)
IF RTRIM$ (DispLine$ (L)) <> "" THEN
A$ = DispLine$ (L)
EXIT FOR
END IF
NEXT
' if it doesn't say 'Error' or
' 'Target', check the next line up
' (since a long error-description
' may have caused the message to
' wrap to a second line ...)
IF INSTR (A$, "): Error ") + INSTR (A$, "): Target ") = 0 THEN
DECR L
A$ = DispLine$ (L)
END IF
IF dbg THEN
PRINT #Debug, " A$ = "; RTRIM$ (A$)
END IF
IF INSTR (A$, "): Error ") + INSTR (A$, "): Target ") = 0 THEN
PLAY "O4 C32 P16 O0 F64"
PRINT "Erfind: NO ERROR FOUND. EXITING TO SYSTEM."
IF dbg THEN
PRINT #Debug, " NO ERROR FOUND. EXITING TO SYSTEM."
PRINT #Debug, ""
END IF
END 1
END IF
' check whether we're dealing with the output of
' a 'PBC /REnnnn' command ... if so the screen reads
' "Target address found" rather than "Error". (This
' means a run-time error; it won't happen unless your
' main program has an error handler that makes it
' happen -- e.g. the upcoming Spring '91 revision of
' APLIB, the All-Purpose PowerBASIC Lirary.)
'
UsingPBCREOutPut = (INSTR (A$, "Target") > 0)
DO WHILE INSTR (A$, "\") ' parse off the path string
A$ = MID$ (A$, INSTR (A$,"\")+1)
LOOP
E$ = MID$ (A$, INSTR(A$, "Error") + 6) ' get the error number
ECode = VAL (E$)
FileName$ = EXTRACT$ (A$, "(") ' get the file name
LineNum = VAL (EXTRACT$ (MID$ (A$, LEN(FileName$)+2), ")")) ' & line number
Extension$ = MID$ (A$, INSTR (A$, ".") + 1, 3)
Extension$ = EXTRACT$ (Extension$, "(")
FileName$ = EXTRACT$ (FileName$, ".") + "." + Extension$
IF dbg THEN
PRINT #Debug, " ERROR "; ECode; " IN "; FileName$; " LINE "; LineNum
PRINT #Debug, ""
END IF
IF NOT UsingPBCREOutPut THEN
LOCATE 25,30: PRINT "PRESS A KEY TO RETURN TO EDITOR ... ";
DO: LOOP UNTIL INKEY$ <> ""
END IF
LOCATE 25,1: PRINT SPACE$ (80);
LOCATE 25,1
IF RD$ = ":" THEN
CLS
LOCATE 5, 1
PRINT " ====================================================="
PRINT " A drive or path for saving temporary files was not
PRINT " found in your DOS environment string. You can put it
PRINT " there later by typing 'SET TEMP=D' or E or whatever
PRINT " the drive letter of your RAM-Disk is. If you don't have
PRINT " a RAM-Disk, a regular disk drive may be used instead;
PRINT " you will want to delete the temporary .BAT files
PRINT " later. For now, enter the drive letter to use.
PRINT " DRIVE & PATH FOR TEMPORARY FILES IS: ";
L = CSRLIN: C = POS
PRINT " ====================================================="
LOCATE L,C: INPUT C$
LOCATE L+1, 79: PRINT: PRINT
C$ = UCASE$ (LEFT$ (C$, 1))
IF C$ < "A" OR C$ > "Z" THEN
BEEP: PRINT "ERROR!": END 1
ELSE
RD$ = C$ + ":"
END IF
END IF
IF DIR$ (RD$ + "GO2ERR.&BA") <> "" THEN KILL RD$ + "GO2ERR.&BA"
IF DIR$ (RD$ + "GO2ERR.BAT") <> "" THEN
NAME RD$ + "GO2ERR.BAT" AS RD$ + "GO2ERR.&BA"
END IF
OPEN RD$ + "GO2ERR.BAT" FOR OUTPUT AS 1 ' create output batch-file
A$ = "@echo off"
PRINT #1, A$
A$ = "Q " + FileName$ + " /n" + LTRIM$ (STR$ (LineNum))
PRINT #1, A$
A$ ="check keyboard"
PRINT #1, A$
A$ ="if errorlevel 1 quit"
PRINT #1, A$
IF DIR$ (RD$ + "colorcls.com") <> "" THEN ' My EGA machine has PC
A$ = RD$ + "colorcls 4E" ' Magazine's COLORCLS.COM
ELSE ' stored on the ramdisk
A$ ="cls"
END IF
PRINT #1, A$
IF COMMAND$ = "" THEN
A$ = "pbc /ce " + FileName$
ELSE
A$ ="pbc /ce " + COMMAND$
END IF
PRINT #1, A$
A$ ="if not errorlevel 1 goto OK"
PRINT #1, A$
A$ ="erfind " + COMMAND$
PRINT #1, A$
A$ ="quit" '
PRINT #1, A$
A$ ="goto end"
PRINT #1, A$
A$ =":OK"
PRINT #1, A$
F$ = EXTRACT$ (COMMAND$, ".")
A$ = "if exist " + F$ + ".EXE " + COMMAND$
PRINT #1, A$
A$ = "if exist \bin\nul if exist \bin\" + F$ + ".EXE " + F$
PRINT #1, A$
A$ =":end"
PRINT #1, A$
CLOSE
CALL BufferStuffer (RD$ + "GO2ERR" + CHR$(13))
END
FUNCTION SCRNLINE$ (L)
LOCAL Ct
LOCAL A$
A$ = ""
FOR Ct = 1 TO 80
A$ = A$ + CHR$ (SCREEN (L, Ct))
NEXT
SCRNLINE$ = A$
END FUNCTION
SUB BufferStuffer (M$)
IF LEN (M$) > 15 THEN PLAY "O2 E32 P8 O1 C4": M$ = "COMMAND"+CHR$(255)+"2 LONG"
L = LEN (M$)
DEF SEG = 0
POKE 1050, 30
POKE 1052, 30 + 2 * L
FOR I = 1 TO L
POKE 1052 + 2*I, ASCII (MID$ (M$,I,1))
NEXT
END SUB
' ___________________________________________________________
SUB ReadNMatchColor
LOCAL A ' sets COLOR to match the
A = SCREEN (CSRLIN, POS, 1) ' color presently on the
COLOR A MOD 16, A \ 16 ' display (at cursor position).
END SUB
' __________________ END OF PROGRAM _____________________